$(document).ready(function(){
	openKeyBoard()
	var pn=location.search.split("?pn=")[1];
	$("#playAgain").one("touchstart",function(){
		window.location.href="game.html?pn="+pn;
	})
	$("#submitInfo").on("touchstart",function(){
		if(checkTel() && checkName()){
			window.location.href="submitSuccess.html";
		}
		else if(!checkTel() && checkName()){
			$("#userTel").val("手机号填写有误，请重填")
			$("#userTel").css({border:"3px solid white"})
			$("#userTel").on("focus",reInput)
		}
		else if(checkTel() && !checkName()){
			$("#userName").val("姓名填写有误，请重填")
			$("#userName").css({border:"2px solid white"})
			$("#userName").on("focus",reInput)
		}
		else if(!checkTel() && !checkName()){
			$("#userName").val("姓名填写有误，请重填")
			$("#userName").css({border:"2px solid white"})
			$("#userTel").val("手机号填写有误，请重填")
			$("#userTel").css({border:"2px solid white"})
			$("#userName,#userTel").on("focus",reInput)
		}
	})
})

//判断是否打开了软键盘
function openKeyBoard(){
	var winHeight = $(window).height();   
	$(window).resize(function(){
		var thisHeight=$(this).height();
		if(winHeight - thisHeight >50){
			$(".divTips2").css({opacity:0})	
		}else{
			$(".divTips2").css({opacity:1})
		}
	});
}

//检查手机号是否合法的的函数
function checkTel(){
	let inputTel=$("#userTel").val();
	var reg3=/^((13[0-9])|(15[0-35-9])|(18[0-9])|(14[0-9]))\d{8}$/;//排除154
	if(reg3.test(inputTel)){
		return true;
	}else{
		return false;
	}
}

//检查姓名是否合法的的函数
function checkName(){
	let inputName=$("#userName").val();
	if(inputName!=""){
		return true;
	}else{
		return false;
	}
}

//重新输入函数
function reInput(){
	$("#userName").css({border:"1px solid #f0ce89"})	
	$("#userName").val("")
	$("#userTel").css({border:"1px solid #f0ce89"})	
	$("#userTel").val("")
	$("#userName,#userTel").off("focus",reInput)
}
